package com.sondon.dev_info.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sondon.dev_info.entity.Company;
import com.sondon.dev_info.service.TemplateManager;

@Controller
public class CompanyController {
	@Resource(name="templateManager")
	public  TemplateManager<Company> templateManager;
	
	@RequestMapping(value="/add_company",method=RequestMethod.GET)
	@ResponseBody
	public Company add_company(){
		Company company=new Company();
		company.setAddress("广州天河华景软件园");
		company.setEmail("123456@qq.com");
		company.setName("广州讯动网络可以有限公司");
		company .setPhone("12345678912");
		templateManager.add(company);
		return company;
	}
//	
//	   @RequestMapping("/get")
//	   public void get(HttpServletRequest req,HttpServletResponse res) {
//	       res.setContentType("text/plain");
//	       String callbackFunName =req.getParameter("callbackparam");//得到js函数名称
//	       try {
//	           res.getWriter().write(callbackFunName + "([ { name:\"John\"}])"); //返回jsonp数据
//	       } catch (IOException e) {
//	           e.printStackTrace();
//	       }
//	   }
//	   
//	   @RequestMapping("/getJsonp")
//	   @ResponseBody
//	   public JSONPObject getJsonp(String callbackparam){
//			Company company=new Company();
//			company.setAddress("广州天河华景软件园");
//			company.setEmail("123456@qq.com");
//			company.setName("广州讯动网络可以有限公司");
//			company .setPhone("12345678912");
//		   return new JSONPObject(callbackparam, company); 
//	   }
	
	@RequestMapping(value="/get_company",method=RequestMethod.GET)
//	@ResponseBody
	
	public ModelAndView get_company(){
		ModelAndView  mav=new ModelAndView("company_info");
		Company company= templateManager.get("1", Company.class);
		mav.addObject(company);
		return mav;
	}
	
	@RequestMapping(value="/get_all_company",method=RequestMethod.GET)
//	@ResponseBody
	public   ModelAndView get_all_company(){
		ModelAndView mav=new ModelAndView("company_info");
		List<Company> companys=templateManager.getAll(Company.class);
		mav.addObject("companylist", companys);
		return mav;
	}
	
	@RequestMapping(value="/del_company",method=RequestMethod.GET)
	@ResponseBody
	public Object del_company(){
		return templateManager.del("1", Company.class);
	}
	
	@RequestMapping(value="/update_company",method=RequestMethod.GET)
	@ResponseBody
	public Object update_company(){
		Company company=templateManager.get("1", Company.class);
		company.setEmail("987654321@qq.com");
		return templateManager.update(company);
	}
}
